{{#if template}}
<template>
  <div class="{{ name }}-container">
    <search-form
      :config-list="searchFormConfig"
      @search="search"
      @reset="reset"
      ref="searchFormRef"
    >
      <template #leftSlot>
        <!--左侧的插槽-->
        <el-button icon="Search" type="primary" @click="handleAdd">
          新增
        </el-button>
      </template>
      <template #rightSlot>
        <!--右侧的插槽-->
      </template>
    </search-form>
    <CustomTable
      :pagination="pagination"
      :table-config="tableConfig"
      @pagination-change="paginationChange"
      @actions-click="actionsClick"
    />
  </div>

</template>
{{/if}}

{{#if script}}
<script>
  export default {
    name: '{{ name }}',
  }
</script>

<script setup>
  import CustomTable from '@/views/component/CustomTable'
  import SearchForm from '@/views/component/SearchForm' //引入搜索组件
  

    // 搜索参数
  const queryForm = ref({})

   const tableConfig = reactive({
    columns: [
      {
        label: 'ID',
        prop: 'id',
        sortable: false,
        width: 120,
        fixed: 'left',
      },
      { label: '岗位名称', prop: 'name', sortable: false, width: 120 },
      {
        label: '招聘部门',
        prop: 'role_name',
        sortable: false,
        width: 120,
      },
      { label: '招聘人数', prop: 'number', sortable: false, width: 120 },
      {
        label: '岗位要求',
        prop: 'recruitment_needs',
        sortable: false,
        showOverflowTooltip: true,
      },
      {
        label: '审批状态',
        prop: 'status',
        sortable: false,
        width: 120,
        customType: 'ElTag',
        tagKeyValue: 'statusTag',
      },
      {
        label: '审批备注',
        prop: 'remarks',
        sortable: false,
        width: 120,
        showOverflowTooltip: true,
      },
      { label: '创建人', prop: 'admin_name', sortable: false, width: 120 },
      { label: '创建时间', prop: 'create_time', sortable: false, width: 180 },
      {
        label: '操作',
        action: true,
        width: 150,
        fixed: 'right',
        actions: [
          {
            fnName: 'approve',
            title: '审批',
            type: 'primary',
            isTextBtn: true,
            permissionCode: 'approveBtn', // 权限
            key: 'status', // 按钮需要判断的值
            showValue: 1, // 判断展示时的值
          },
        ],
      },
    ],
    tagConfig: {
      //审批状态 1:审批中 2:审批通过 3:审核不通过
      statusTag: {
        1: {
          name: '审批中',
          type: 'success',
        },
        2: {
          name: '审批通过',
          type: 'primary',
        },
        3: {
          name: '审核不通过',
          type: 'warning',
        },
      },
    },
    list: [],
    listLoading: false,
  })


  //搜索组件配置信息
  const searchFormConfig = reactive({
    config: {
      layoutType: 1, //1:左右布局,2:上下布局
      leftPanelWidth: 0, //控制左边布局控件宽度
    },
    controlList: [
      { label: '岗位名称', prop: 'name', type: 'input' },
      {
        label: '审批状态',
        prop: 'status',
        type: 'select',
        list: Object.keys(tableConfig['tagConfig']['statusTag']).reduce(
          (acc, cur) => {
            const { name } = tableConfig['tagConfig']['statusTag'][cur]
            acc.push({ label: name, value: cur })
            return acc
          },
          []
        ),
      },
      {
        label: '创建人',
        prop: 'admin_id',
        type: 'select',
        list: [],
      },
    ],
  })

    //点击搜索触发
  const search = (form) => {
    console.log(form)
    pagination.page = 1
    queryForm.value = form
    queryProject()
  }

    //列表分页参数
  const pagination = reactive({
    page: 1, //每页条数
    limit: 10, //当前页
    total: 0,
    layout: 'total, sizes, prev, pager, next, jumper',
  })

    //分页控件点击操作
  const paginationChange = (data) => {
    const { val, type } = data
    pagination[type] = val
    queryProject()
  }

  //请求列表数据
  const queryProject = () => {
    tableConfig.listLoading = true
    getList({
      ...queryForm.value,
      limit: pagination.limit,
      page: pagination.page,
    })
      .then((result) => {
        console.log('result', result)
        tableConfig.list = result.data.data
        tableConfig.listLoading = false
        pagination.total = result.data.total
      })
      .catch(() => {
        tableConfig.listLoading = false
      })
  }

  //点击表格操作按钮回调
  const actionsClick = (data) => {
    console.log('actionsClick===', data)
    const { type, row } = data
    switch (type) {
    }
  }

  const searchFormRef = ref(null)
  const reset = () => {
    if (!searchFormRef.value) return
    searchFormRef.value.resetFormFields()
    queryProject()
  }

   const init = async () => {
    await queryProject()
  }

  init()



</script>
{{/if}}

{{#if style}}
<style lang="scss" scoped>

</style>
{{/if}}
